home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / utils / newbench / newbench.asm < prev   
Assembly Source File  |  1980-01-03  |  9KB  |  389 lines

  1. ;#copy %s t:temp.asm
  2. ;#default t:temp.asm
  3. ;#delete %f
  4. ;#rename temp %f
  5. ;#copy %f rram:
  6. ;
  7. ; ### NewBench by JM v 1.05 ###
  8. ;
  9. ; - Created 891213 by JM -
  10. ;
  11. ;
  12. ; This program opens extra Workbench Screens and closes them.
  13. ;
  14. ;
  15. ;
  16. ;
  17. ; Bugs: yet unknown
  18. ;
  19. ;
  20. ; Edited:
  21. ;
  22. ; - 891213 by JM -> v0.01    - Source from Wati.asm.
  23. ; - 891213 by JM -> v0.02    - Works.
  24. ; - 891213 by JM,TM -> v0.10    - Command line parser.
  25. ; - 891213 by JM -> v1.00    - Screen size limiting added.
  26. ;                - Initial message added.
  27. ; - 891214 by JM -> v1.01    - Code compressing, (c) message added.
  28. ; - 891215 by JM -> v1.02    - Now recognizes NTSC mode and handles screen
  29. ;                  limits more intelligently.
  30. ; - 891215 by JM -> v1.03    - Some compressing...
  31. ; - 900317 by JM -> v1.04    - No longer closes screens that no longer
  32. ;                  exist.
  33. ; - 900803 by JM -> v1.05    - No longer exits while Forbidden.
  34. ;
  35. ;
  36.  
  37.  
  38.  
  39.         include    "exec.xref"
  40.         include    "dos.xref"
  41.         include    "intuition.xref"
  42.         include    "JMPLibs.i"
  43.         include    "relative.i"
  44.         include    "com.i"
  45.         include    "constants.i"
  46.         include    "exec/types.i"
  47.         include    "exec/nodes.i"
  48.         include    "exec/lists.i"
  49.         include    "exec/ports.i"
  50.         include    "exec/memory.i"
  51.         include    "exec/devices.i"
  52.         include    "exec/io.i"
  53.         include    "exec/tasks.i"
  54.         include    "exec/execbase.i"
  55.         include    "dosextens.i"
  56.         include    "devices/input.i"
  57.         include    "devices/inputevent.i"
  58.         include    "intuition/intuitionbase.i"
  59.         include    "intuition/screens.i"
  60.         include    "graphics/gfxbase.i"
  61.  
  62.  
  63. strcpy        macro    * a0,a1
  64. strcpy\@    move.b    (\1)+,(\2)+
  65.         bne.s    strcpy\@
  66.         endm
  67.  
  68.  
  69. RELATIVE    equ    1
  70. MAXSCREEN    equ    16
  71.  
  72.  STRUCTURE  GlobalPort,MP_SIZE
  73.     STRUCT  gp_scrs,4*MAXSCREEN
  74.     STRUCT  gp_name,24
  75.     STRUCT  gp_title,24
  76.  LABEL gp_sizeof
  77.  
  78.  
  79.         .var    global        allocates variables from stack
  80.         dl    .DosBase     using LINK a4,#-size
  81.         dl    .IntuitionBase
  82.         dl    .GfxBase
  83.         dl    globport,newscr
  84.         dl    cmdlin
  85.  
  86.  
  87. start        .begin                this turns to LINK a4,#-NN
  88.         clr.b    -1(a0,d0)        NULL terminate cmd line
  89.         move.l    a0,cmdlin(a4)
  90.  
  91.         move.l    a4,a0            let's clear the variables
  92.         clr.l    -(a0)
  93.         clr.l    -(a0)
  94.         clr.l    -(a0)
  95.         clr.l    -(a0)
  96.  
  97.         openlib    Dos,cleanup        open dos.library ..
  98.         openlib    Intuition,cleanup    intuition.library ..
  99.         openlib    Gfx,cleanup        and gfx.library
  100.  
  101.         lea    MESSAGE(pc),a2        output initial message
  102.         bsr    print
  103.  
  104.         lea    NS_temp,a1        copy default newscreen data
  105.         move.l    a1,newscr(a4)        save ptr for later use
  106.         lea    NS(pc),a0
  107.         moveq    #ns_SIZEOF-1,d0
  108. 1$        move.b    (a0)+,(a1)+
  109.         dbf    d0,1$
  110.  
  111.         lea    portname(pc),a1        test if port already exists
  112.         lib    Exec,FindPort
  113.         move.l    d0,globport(a4)
  114.  
  115.         move.l    cmdlin(a4),a0        address of cmd line
  116.         move.l    newscr(a4),a1
  117.         bsr    pars            parse parameters
  118.         bcs.s    cleanup
  119.         beq.s    Remove
  120.  
  121. MoreScreen    move.l    globport(a4),d0
  122.         bne.s    Install1        -> port already exists
  123. Install        bsr    CreatePort        create messageport
  124.         bcs.s    cleanup            -> can't CreatePort()
  125. Install1    bsr    MakeScreen
  126.         bcc.s    cleanup
  127.         lea    OSERR(pc),a2
  128.         bsr    print
  129.         bra.s    cleanup
  130.  
  131. Remove        move.l    globport(a4),d0
  132.         beq.s    cleanup            -> no port exists
  133.         bsr    RemoveScreens
  134.         bne.s    cleanup            screens still open
  135.         bsr    DeletePort        delete messageport
  136.  
  137. cleanup        closlib    Gfx
  138.         closlib    Intuition        close intuition.library
  139.         closlib    Dos            close dos.library
  140.         moveq.l    #0,d0
  141.         .end                UNLK and RTS
  142.  
  143.  
  144.  
  145. *************************************************************************
  146. *                                    *
  147. * Create messageport so that the screen pointers can be found by this    *
  148. * program when run again.                        *
  149. *                                    *
  150. * This messageport stays in memory as long as any of the screens is    *
  151. * open.                                    *
  152. *                                    *
  153. *************************************************************************
  154.  
  155. CreatePort    move.l    #gp_sizeof,d0
  156.         move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1
  157.         lib    Exec,AllocMem
  158.         move.l    d0,globport(a4)
  159.         beq.s    CreatePort_e
  160.         move.l    d0,a2
  161.         clr.b    LN_PRI(a2)
  162.         move.b    #NT_MSGPORT,LN_TYPE(a2)
  163.  
  164.         lea    gp_name(a2),a1        space for port name
  165.         move.l    a1,LN_NAME(a2)
  166.         lea    portname(pc),a0
  167.         strcpy    a0,a1            copy name into myport
  168.  
  169.         lea    gp_title(a2),a1        space for screen title
  170.         lea    title(pc),a0
  171.         strcpy    a0,a1            copy title
  172.  
  173.         move.l    a2,a1
  174.         flib    Exec,AddPort        AddPort!  - Crash!? - No.
  175.         clrc
  176.         rts
  177.  
  178. CreatePort_e    setc
  179.         rts
  180.  
  181.  
  182. DeletePort    move.l    globport(a4),d2        get pointer to port
  183.         beq.s    DeletePort_ok        if NULL nothing to delete
  184.         move.l    d2,a1
  185.         lib    Exec,RemPort        remove port from system list
  186.         move.l    #gp_sizeof,d0
  187.         move.l    d2,a1
  188.         flib    Exec,FreeMem        free the memory used by port
  189. DeletePort_ok    rts
  190.  
  191.  
  192.  
  193.  
  194. MakeScreen    move.l    globport(a4),a2        get pointer to port
  195.         lea.l    gp_scrs(a2),a2
  196.         moveq    #MAXSCREEN-1,d0        max. number of screens
  197. 1$        tst.l    (a2)+            search for an empty ptr
  198.         dbeq    d0,1$
  199.         beq.s    MakeScreen1
  200. MakeScreen_e    setc
  201.         rts
  202. MakeScreen1    move.l    newscr(a4),a0        NewScreen structure
  203.         move.l    globport(a4),a1
  204.         lea    gp_title(a1),a1        title string in our port
  205.         move.l    a1,ns_DefaultTitle(a0)    set title to NewScreen
  206.  
  207.         move.w    #800,d2            Xmax
  208.         move.w    #600,d3            Ymax for PAL
  209.         move.w    #300,d4            limit for LACE
  210.  
  211.         move.l    .GfxBase(a4),a1        check if PAL system?
  212.         btst    #2,gb_DisplayFlags+1(a1)
  213.         bne.s    1$            .ne -> yup
  214.         move.w    #470,d3            Ymax for NTSC
  215.         move.w    #240,d4            new limit for LACE
  216.  
  217. 1$        move.w    ns_Depth(a0),d0        depth of requested screen
  218.         subq.w    #4,d0
  219.         bls.s    2$            4 or less planes
  220.         move.w    #352,d2            Xmax for >4 bitplanes
  221.         subq.w    #2,d0            check if illegal size
  222.         bhi.s    MakeScreen_e        too deep -> error
  223. 2$        cmp.w    ns_Width(a0),d2
  224.         blo.s    MakeScreen_e        too wide -> error
  225.         cmp.w    ns_Height(a0),d3
  226.         blo.s    MakeScreen_e        too high -> error
  227.  
  228.         moveq    #0,d0
  229.         cmp.w    #352,ns_Width(a0)
  230.         bls.s    100$
  231.         or.w    #V_HIRES,d0        Width > 352 -> HIRES
  232. 100$        cmp.w    ns_Height(a0),d4
  233.         bhs.s    110$
  234.         or.w    #V_LACE,d0        Height > limit -> LACE
  235. 110$        move.w    d0,ns_ViewModes(a0)
  236.  
  237.         lib    Intuition,OpenScreen
  238.         move.l    d0,-(a2)
  239.         beq.s    MakeScreen_e        couldn't OpenScreen
  240.         rts
  241.  
  242.  
  243. RemoveScreens    move.l    globport(a4),a2
  244.         lea.l    gp_scrs(a2),a2
  245.         moveq    #0,d3            flag: screens open
  246.         moveq    #MAXSCREEN-1,d2
  247. 1$        move.l    (a2)+,d0
  248.         bne.s    3$
  249. 4$        dbf    d2,1$
  250.         move.l    d3,d0            # of screens still open
  251.         rts
  252. 3$        push    d0
  253.         lib    Exec,Forbid
  254.         pull    d0
  255.         move.l    .IntuitionBase(a4),a0
  256.         move.l    ib_FirstScreen(a0),a0
  257. 31$        move.l    a0,d1
  258.         beq.s    2$            screen no longer exists
  259.         cmp.l    d1,d0            this screen found?
  260.         beq.s    32$            yep -> okay to close it
  261.         move.l    sc_NextScreen(a0),a0
  262.         bra.s    31$
  263. 32$        move.l    d0,a0
  264.         tst.l    sc_FirstWindow(a0)    windows open?
  265.         bne.s    2$
  266.         lib    Intuition,CloseScreen
  267.         clr.l    -4(a2)
  268.         bra.s    5$
  269. 2$        addq.l    #1,d3            yup -> incr cntr
  270. 5$        lib    Exec,Permit
  271.         bra.s    4$
  272.  
  273.         
  274.  
  275. *************************************************************************
  276. *                                    *
  277. * Check for a command:                            *
  278. *                                    *
  279. *************************************************************************
  280.  
  281. pars        ;a0=cmdlin, a1=newscreen; p.z=cmd
  282.         ;handle the command line parameters:
  283.         moveq    #0,d2            ;no R gotten yet
  284. 100$        move.b    (a0)+,d0        ;get one character
  285.         beq.s    pars_end        ;no more?
  286.         cmp.b    #32,d0            ;if space, get next
  287.         beq.s    100$
  288.         cmp.b    #'a',d0
  289.         blo.s    101$
  290.         cmp.b    #'z',d0
  291.         bhi.s    101$            ;lower-case alphabet?
  292.         sub.b    #32,d0            ;convert to upper case
  293. 101$        cmp.b    #'D',d0
  294.         bne.s    200$
  295.         bsr.s    pars_cvlo        ;get depth
  296.         bcs.s    pars_usage        ;error?
  297.         move.w    d0,ns_Depth(a1)        ;no, assign it there
  298.         bra.s    100$            ;and go for next parameter
  299. 200$        cmp.b    #'W',d0
  300.         bne.s    300$
  301.         bsr.s    pars_cvlo        ;get width
  302.         bcs.s    pars_usage        ;error?
  303.         move.w    d0,ns_Width(a1)        ;no, assign width
  304.         bra.s    100$            ;and get next parameter
  305. 300$        cmp.b    #'H',d0
  306.         bne.s    400$
  307.         bsr.s    pars_cvlo        ;get height
  308.         bcs.s    pars_usage        ;error?
  309.         move.w    d0,ns_Height(a1)    ;no, assign that for height
  310.         bra.s    100$            ;and get the next one
  311. 400$        cmp.b    #'R',d0
  312.         bne.s    500$
  313.         move.b    d0,d2            ;save the R (remove) flag
  314.         bra.s    100$
  315. 500$        ;now it was some unidentified character:
  316. pars_usage    lea.l    pars_usage.(pc),a2    ;print out
  317.         bsr.s    print            ;  "usage: bla bla bla"
  318.         setc                ;and return an error
  319.         rts                ;/otherwise:
  320. pars_end    cmp.b    #'R',d2            ;was there an R somewhere?
  321.         clrc                ;return OK
  322.         rts
  323.  
  324. pars_cvlo    ;get a base-10 number:
  325.         ;(for technical reasons does not accept the value 0)
  326.         moveq    #0,d0            ;clear the result
  327. 1$        moveq    #0,d1
  328.         move.b    (a0)+,d1        ;get one digit
  329.         cmp.b    #'9',d1            ;greater than "9" ..
  330.         bhi.s    2$
  331.         sub.b    #'0',d1            ;.. or less than "0"?
  332.         blo.s    2$            ;if so, go ->
  333.         add.l    d0,d0            ;otherwise * result by 2
  334.         add.l    d0,d1            ;and save
  335.         asl.l    #2,d0            ;multiply by 4
  336.         add.l    d1,d0            ;and add the by-2 and ..
  337.         bra.s    1$            ;.. the digit and get next one
  338. 2$        ;now some other character than a numeric digit was found:
  339.         subq.l    #1,a0            ;go back to that dummy
  340.         tst.l    d0            ;any value gotten this far?
  341.         bne.s    3$            ;yes, return no error
  342.         setc                ;no, return error
  343. 3$        rts
  344.  
  345.  
  346. print        lib    Dos,Output
  347.         move.l    d0,d1
  348.         beq.s    print_e            no output file handle
  349.         moveq    #0,d3
  350.         move.b    (a2)+,d3        length
  351.         move.l    a2,d2
  352.         flib    Dos,Write        output text
  353. print_e        rts
  354.  
  355.  
  356. NS        dc.w    0,0,640,256,2        x,y,xs,ys,dpth
  357.         dc.b    0,1            block,detail
  358.         dc.w    V_SPRITES        viewmodes
  359.         dc.w    WBENCHSCREEN        type
  360.         dc.l    0            text attr
  361.         dc.l    0            title
  362.         dc.l    0            ggs
  363.         dc.l    0            bm
  364.  
  365.  
  366. portname    equ    *
  367. title        dc.b    'NewBenchScreen',0
  368. MESSAGE        dc.b    38,'NewBench v1.05 by Supervisor Software',LF
  369. OSERR        dc.b    06,'Error',LF
  370. pars_usage.    dc.b    46            ;text length here!
  371.             ;01234567890123456789012345678901234567890123456789
  372.         dc.b    'Usage: newbench ([Ddepth][Wwidth][Hheight])|R',LF
  373.         ds.w    0
  374.  
  375.  
  376. *************************************************************************
  377. *                                    *
  378. * This macro produces the library names in this program.        *
  379. *                                    *
  380. *************************************************************************
  381.  
  382.         libnames
  383.  
  384.         section    help,bss
  385. NS_temp        ds.b    ns_SIZEOF
  386.  
  387.         end
  388.  
  389.